local extension = Package("fengqi_thunder")
extension.extensionName = "aaa_fengqi"

local U = require "packages/utility/utility"

Fk:loadTranslationTable{
  ["fengqi_thunder"] = "雷",
}


local chendao = General:new(extension, "efengqi__chendao", "han", 4)
local tonglie = fk.CreateTriggerSkill{
  name = "efengqi__tonglie",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.CardUsing,fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if target == player  then
      if event == fk.CardUsing then
        return player.phase == Player.Play and (table.contains(player:getTableMark("@[efengqi__tonglie]"), "efengqi__tonglie1") or
          (player:hasSkill(self) and not table.contains(player:getTableMark("efengqi__tonglie_removed"), "efengqi__tonglie1"))) and
          #player.room.logic:getEventsOfScope(GameEvent.UseCard, 2, function (e)
            return e.data[1].from == player.id
          end, Player.HistoryPhase) == 1
      elseif event == fk.EventPhaseStart then
        return player.phase == Player.Finish and player:hasSkill(self) and #player:getTableMark("efengqi__tonglie_removed") < 3 and #player.room:getOtherPlayers(player) > 0
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.CardUsing then
      data.disresponsiveList = table.map(room.players, Util.IdMapper)
    elseif event == fk.EventPhaseStart then
      local success, dat = room:askForUseActiveSkill(player, "efengqi__tonglie_active", "#efengqi__tonglie-give", true, nil, false)
      if success and dat then
        local choice = dat.interaction
        local to = room:getPlayerById(dat.targets[1])
        room:addTableMark(player, "efengqi__tonglie_removed", choice)
        if #to:getTableMark("efengqi__tonglie_removed") > 0 then
          room:removeTableMark(to, "efengqi__tonglie_removed", choice)
        else
          room:addTableMark(to, "@[efengqi__tonglie]", choice)
        end
        if player:getHandcardNum() < 4 then
          player:drawCards(4 - player:getHandcardNum(), self.name)
        end
      end
    end
  end,

  refresh_events = {fk.AfterCardUseDeclared, fk.PreCardUse},
  can_refresh = function(self, event, target, player, data)
    if target == player and player.phase == Player.Play then
      if event == fk.AfterCardUseDeclared then
        return true
      elseif (table.contains(player:getTableMark("@[efengqi__tonglie]"), "efengqi__tonglie2") or
        (player:hasSkill(self) and not table.contains(player:getTableMark("efengqi__tonglie_removed"), "efengqi__tonglie2"))) then
        return player:getMark("efengqi__tonglie-phase") < 2
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    if event == fk.AfterCardUseDeclared then
      player.room:addPlayerMark(player, "efengqi__tonglie-phase", 1)
    elseif event == fk.PreCardUse then
      data.extraUse = true
    end
  end,
}
local tonglie_active = fk.CreateActiveSkill{
  name = "efengqi__tonglie_active",
  card_num = 0,
  target_num = 1,
  interaction = function(self)
    local all_choices = {"efengqi__tonglie1", "efengqi__tonglie2", "efengqi__tonglie3"}
    local choices = table.filter(all_choices, function (str)
      return not table.contains(Self:getTableMark("efengqi__tonglie_removed"), str)
    end)
    return UI.ComboBox { choices = choices, all_choices = all_choices }
  end,
  card_filter = Util.FalseFunc,
  target_filter = function (self, to_select, selected)
    if #selected == 0 and to_select ~= Self.id then
      local target = Fk:currentRoom():getPlayerById(to_select)
      return not target:hasSkill(tonglie, true) and
        not table.contains(target:getTableMark("efengqi__tonglie_removed"), self.interaction.data)
    end
  end,
}
local tonglie_targetmod = fk.CreateTargetModSkill{
  name = "#efengqi__tonglie_targetmod",
  bypass_distances =  function(self, player, skill)
    if (table.contains(player:getTableMark("@[efengqi__tonglie]"), "efengqi__tonglie3") or
      (player:hasSkill(tonglie) and not table.contains(player:getTableMark("efengqi__tonglie_removed"), "efengqi__tonglie2"))) then
      return player.phase == Player.Play and player:getMark("efengqi__tonglie-phase") < 3
    end
  end,
  bypass_times = function(self, player, skill, scope)
    if (table.contains(player:getTableMark("@[efengqi__tonglie]"), "efengqi__tonglie2") or
      (player:hasSkill(tonglie) and not table.contains(player:getTableMark("efengqi__tonglie_removed"), "efengqi__tonglie2"))) then
      return player.phase == Player.Play and player:getMark("efengqi__tonglie-phase") < 2
    end
  end,
}
Fk:addQmlMark{
  name = "efengqi__tonglie",
  how_to_show = function(name, value)
    if type(value) == "table" then
      return tostring(#value)
    end
    return " "
  end,
  qml_path = "packages/aaa_fengqi/qml/Tonglie"
}
Fk:addSkill(tonglie_active)
tonglie:addRelatedSkill(tonglie_targetmod)
chendao:addSkill(tonglie)
Fk:loadTranslationTable{
  ["efengqi__chendao"] = "陈到",
  ["#efengqi__chendao"] = "白毦督",
  ["illustrator:efengqi__chendao"] = "梦回唐朝",
  ["designer:efengqi__chendao"] = "汤圆",

  ["efengqi__tonglie"] = "统烈",
  [":efengqi__tonglie"] = "锁定技，你于出牌阶段使用的：首张牌无法被响应；前两张牌无次数限制；前三张牌无距离限制。结束阶段，你可以"..
  "交出一项效果并将手牌摸至四张。",
  ["efengqi__tonglie_active"] = "统烈",
  ["#efengqi__tonglie-give"] = "统烈：你可以将一项效果交给其他角色并将手牌摸至四张",
  ["@[efengqi__tonglie]"] = "统烈",
  ["efengqi__tonglie1"] = "使用首张牌无法被响应",
  ["efengqi__tonglie2"] = "使用前两张牌无次数限制",
  ["efengqi__tonglie3"] = "使用前三张牌无距离限制",

  ["$efengqi__tonglie1"] = "猛将之烈，统帅之所往。",
  ["$efengqi__tonglie2"] = "与子龙忠勇相往，猛烈相合。",
  ["~efengqi__chendao"] = "我的白毦兵，再也不能为先帝出力了。",
}

local lukang = General(extension, "efengqi__lukang", "wu", 3)
local huairou = fk.CreateActiveSkill{
  name = "efengqi__huairou",
  anim_type = "drawcard",
  card_num = 1,
  target_num = 0,
  prompt = "#efengqi__huairou",
  times = function(self)
    return Self.phase == Player.Play and 3 - Self:usedSkillTimes(self.name, Player.HistoryPhase) or -1
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) < 3
  end,
  card_filter = function(self, to_select, selected)
    if #selected == 0 then
      if Fk:getCardById(to_select).type ~= Card.TypeBasic then
        return true
      end
      if Self:getMark("efengqi__jueyan1") > 0 and
        Fk:getCardById(to_select).trueName == "slash" then
        return true
      end
    end
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    if player:getMark("efengqi__jueyan2") > 0 and Fk:getCardById(effect.cards[1]).type == Card.TypeEquip then
      player:addSkillUseHistory(self.name, -1)
    end
    room:recastCard(effect.cards, player, self.name)
    if not player.dead and table.contains(room.discard_pile, effect.cards[1]) and
    Fk:getCardById(effect.cards[1]).type ~= Card.TypeEquip then
      U.askForUseRealCard(room, player, effect.cards, nil, self.name,
        "#efengqi__huairou-use", {
          bypass_times = true,
          extraUse = true,
          expand_pile = effect.cards,
        }, false, true)
    end
  end,
}
local jueyan = fk.CreateTriggerSkill{
  name = "efengqi__jueyan",
  anim_type = "support",
  events = {fk.EventPhaseStart, fk.AreaAborted},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      if event == fk.EventPhaseStart then
        return player.phase == Player.Start and
          (#player:getAvailableEquipSlots() > 0 or not table.contains(player.sealedSlots, Player.JudgeSlot))
      elseif event == fk.AreaAborted then
        return #player:getAvailableEquipSlots() == 0 and table.contains(player.sealedSlots, Player.JudgeSlot)
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    if event == fk.EventPhaseStart then
      local choices = {}
      if #player:getAvailableEquipSlots() > 0 then
        table.insert(choices, "$Equip")
      end
      if not table.contains(player.sealedSlots, Player.JudgeSlot) then
        table.insert(choices, "JudgeSlot")
      end
      table.insert(choices, "Cancel")
      local choice = player.room:askForChoice(player, choices, self.name, "#efengqi__jueyan-invoke")
      if choice ~= "Cancel" then
        self.cost_data = {choice = choice}
        return true
      end
    elseif event == fk.AreaAborted then
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      if self.cost_data.choice == "$Equip" then
        room:setPlayerMark(player, "efengqi__jueyan1", 1)
        room:abortPlayerArea(player, player:getAvailableEquipSlots())
      else
        room:setPlayerMark(player, "efengqi__jueyan2", 1)
        room:abortPlayerArea(player, "JudgeSlot")
      end
    elseif event == fk.AreaAborted then
      room:addPlayerMark(player, MarkEnum.AddMaxCards, 3)
      room:setPlayerMark(player, self.name, 1)
    end
  end,
}
local jueyan_targetmod = fk.CreateTargetModSkill{
  name = "#efengqi__jueyan_targetmod",
  bypass_distances =  function(self, player, skill)
    return player:getMark("efengqi__jueyan") > 0
  end,
}
jueyan:addRelatedSkill(jueyan_targetmod)
lukang:addSkill(huairou)
lukang:addSkill(jueyan)
Fk:loadTranslationTable{
  ["efengqi__lukang"] = "陆抗",
  ["#efengqi__lukang"] = "社稷之瑰宝",
  ["illustrator:efengqi__lukang"] = "第七个桔子",
  ["designer:efengqi__lukang"] = "屑",

  ["efengqi__huairou"] = "怀柔",
  [":efengqi__huairou"] = "出牌阶段限三次，你可以重铸一张非基本牌。若不为装备牌，你可以使用此牌。",
  ["efengqi__jueyan"] = "决堰",
  [":efengqi__jueyan"] = "准备阶段，你可以废除装备区/判定区，令〖怀柔〗可以重铸【杀】/重铸装备牌不计次数。均废除后，你使用牌"..
  "无距离限制且手牌上限+3。",
  ["#efengqi__huairou"] = "怀柔：重铸一张牌，若不为装备可以使用之",
  ["#efengqi__huairou-use"] = "怀柔：你可以使用这张牌",
  ["#efengqi__jueyan-invoke"] = "决堰：废除装备区，令“怀柔”可以重铸【杀】；或废除判定区，令“怀柔”重铸装备牌不计次数",

  ["$efengqi__huairou1"] = "各保分界，无求细利。",
  ["$efengqi__huairou2"] = "胸怀千万，彰其德，包其柔。",
  ["$efengqi__jueyan1"] = "毁堰坝之计，实为阻晋粮道。",
  ["$efengqi__jueyan2"] = "堰坝毁之，可令敌军自退。",
  ["~efengqi__lukang"] = "吾即亡矣，吴又能存几时？",
}

local zhangxiu = General(extension, "efengqi__zhangxiu", "qun", 4)
Fk:loadTranslationTable{
  ["efengqi__zhangxiu"] = "张绣",
  ["#efengqi__zhangxiu"] = "北地枪王",
  ["cv:efengqi__zhangxiu"] = "",
  ["designer:efengqi__zhangxiu"] = "柠檬",
  ["illustrator:efengqi__zhangxiu"] = "鬼画府",
  ["~efengqi__zhangxiu"] = "若失文和，吾将何归？",
}
local congjian = fk.CreateTriggerSkill{
  name = "efengqi__congjian",
  anim_type = "drawcard",
  events = {fk.TargetConfirmed, fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.card.type == Card.TypeTrick and not player:isKongcheng() then
      if event == fk.TargetSpecified and not data.firstTarget then return false end
      return table.find(AimGroup:getAllTargets(data.tos), function (pid)
        return pid ~= player.id
      end)
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = AimGroup:getAllTargets(data.tos)
    table.removeOne(targets, player.id)
    local tos, cardId = room:askForChooseCardAndPlayers(player, targets, 1, 1, ".|.|.|hand", "#efengqi__congjian-give", self.name, true)
    if #tos > 0 then
      self.cost_data = {tos = tos, cards = {cardId}}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data.tos[1])
    room:obtainCard(to, self.cost_data.cards, true, fk.ReasonGive, player.id, self.name)
    if not player.dead then
      player:drawCards(1, self.name)
      if not player.dead and not to.dead and room:askForSkillInvoke(to, self.name, nil, "#efengqi__congjian-ask:"..player.id) then
        room:doIndicate(to.id, {player.id})
        player:drawCards(1, self.name)
      end
    end
  end,
}
zhangxiu:addSkill(congjian)
Fk:loadTranslationTable{
  ["efengqi__congjian"] = "从谏",
  [":efengqi__congjian"] = "当你指定或成为锦囊牌的目标后，可以将一张手牌交给不为你的目标角色，然后摸一张牌，其可以令你再摸一张牌。",
  ["#efengqi__congjian-give"] = "从谏：你可将一张手牌交给不为你的目标角色，摸1张牌，且其可令你再摸1张牌",
  ["#efengqi__congjian-ask"] = "从谏：你可以令 %src 摸一张牌",

  ["$efengqi__congjian1"] = "听君谏言，去危亡，保宗祀",
  ["$efengqi__congjian2"] = "从谏良计，可得自保！",
}
local xiongluan = fk.CreateTriggerSkill{
  name = "efengqi__xiongluan",
  anim_type = "offensive",
  frequency = Skill.Limited,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and player.phase == Player.Start then
      return player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and
      (#player:getAvailableEquipSlots() > 0 or not table.contains(player.sealedSlots, Player.JudgeSlot))
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local tos = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player, false), Util.IdMapper), 1, 1,
    "#efengqi__xiongluan-choose", self.name, true)
    if #tos > 0 then
      self.cost_data = {tos = tos}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data.tos[1])

    local eqipSlots = player:getAvailableEquipSlots()
    if not table.contains(player.sealedSlots, Player.JudgeSlot) then
      table.insert(eqipSlots, Player.JudgeSlot)
    end
    room:abortPlayerArea(player, eqipSlots)
    if not to.dead then
      room:setPlayerMark(to, "@@efengqi__xiongluan-turn", 1)
    end
    if not player.dead then
      room:setPlayerMark(player, "@@efengqi__xiongluan_owner", 1)
      player:filterHandcards()
    end
  end,
}
local xiongluan_prohibit = fk.CreateProhibitSkill{
  name = "#efengqi__xiongluan_prohibit",
  prohibit_use = function(self, player, card)
    if player:getMark("@@efengqi__xiongluan-turn") > 0 then
      local subcards = Card:getIdList(card)
      return #subcards > 0 and table.every(subcards, function(id)
        return table.contains(player:getCardIds(Player.Hand), id)
      end)
    end
  end,
  prohibit_response = function(self, player, card)
    if player:getMark("@@efengqi__xiongluan-turn") > 0 then
      local subcards = Card:getIdList(card)
      return #subcards > 0 and table.every(subcards, function(id)
        return table.contains(player:getCardIds(Player.Hand), id)
      end)
    end
  end,
}
xiongluan:addRelatedSkill(xiongluan_prohibit)
local xiongluan_filter = fk.CreateFilterSkill{
  name = "#efengqi__xiongluan_filter",
  card_filter = function(self, card, player)
    return player and card and player:getMark("@@efengqi__xiongluan_owner") ~= 0 and
    table.contains(player.player_cards[Player.Hand], card.id) and (card.trueName == "slash" or card.type == Card.TypeEquip)
  end,
  view_as = function(self, card)
    local c = Fk:cloneCard("hanqing__enemy_at_the_gates", card.suit, card.number)
    c.skillName = xiongluan.name
    return c
  end,
}
xiongluan:addRelatedSkill(xiongluan_filter)
zhangxiu:addSkill(xiongluan)

Fk:loadTranslationTable{
  ["efengqi__xiongluan"] = "雄乱",
  [":efengqi__xiongluan"] = "限定技，准备阶段，你可以废除装备区和判定区，令一名其他角色本回合不能使用或打出手牌。此后你的【杀】和装备牌均视为【兵临城下】。",
  ["#efengqi__xiongluan-choose"] = "雄乱：你可废除装备区和判定区，令一名其他角色本回合不能使用或打出手牌。本局【杀】和装备视为【兵临城下】",
  ["@@efengqi__xiongluan-turn"] = "被雄乱",
  ["@@efengqi__xiongluan_owner"] = "雄乱",
  ["#efengqi__xiongluan_filter"] = "雄乱",
  ["$efengqi__xiongluan1"] = "北地枭雄，乱世不败！！",
  ["$efengqi__xiongluan2"] = "雄据宛城，虽乱世可安！",
}


local haozhao = General:new(extension, "efengqi__haozhao", "wei", 4)
Fk:loadTranslationTable{
  ["efengqi__haozhao"] = "郝昭",
  ["#efengqi__haozhao"] = "",
  ["designer:efengqi__haozhao"] = "低调的温柔",
  ["illustrator:efengqi__haozhao"] = "",
  ["~efengqi__haozhao"] = "镇守陈仓，也有一失。",
}

---@param victim ServerPlayer
---@param source ServerPlayer
local doZhengu = function (victim, source, choice)
  if victim.dead then return end
  local room = victim.room
  local skill = "efengqi__zhengu"
  if choice == "efengqi__zhengu_damage" then
    victim:drawCards(2, skill)
    if not victim.dead then
      room:doIndicate(source.id, {victim.id})
      room:damage { from = source, to = victim, damage = 1, skillName = skill, damageType = fk.IceDamage }
    end
  else
    local x = victim:getHandcardNum() - source:getHandcardNum()
    if x > 0 then
      room:askForDiscard(victim, x, x, false, skill, false)
    elseif x < 0 then
      victim:drawCards(-x, skill)
    end
  end
end
local zhengu = fk.CreateTriggerSkill{
  name = "efengqi__zhengu",
  anim_type = "control",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Finish
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper),
      1, 1, "#efengqi__zhengu-choose", self.name, true)
    if #to > 0 then
      self.cost_data = {tos = to}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data.tos[1])
    local chosen = {}
    for i = 1, 2 do
      local choice = room:askForChoice(player, {"efengqi__zhengu_damage", "efengqi__zhengu_adjust"},
      self.name, "#efengqi__zhengu-choice:"..to.id.."::"..i)
      table.insert(chosen, choice)
    end
    if chosen[1] ~= chosen[2] then
      for _, ch in ipairs(chosen) do
        doZhengu(to, player, ch)
      end
    else
      room:addTableMark(to, "@@efengqi__zhengu", {player.id, chosen[2]})
      doZhengu(to, player, chosen[1])
    end
  end,
}
local zhengu_delay = fk.CreateTriggerSkill{
  name = "#efengqi__zhengu_delay",
  events = {fk.TurnEnd},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("@@efengqi__zhengu") ~= 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local invoked = {}
    local mark = player:getMark("@@efengqi__zhengu")
    room:setPlayerMark(player, "@@efengqi__zhengu", 0)
    for _, info in ipairs(mark) do
      if player.dead then return end
      local from = room:getPlayerById(info[1])
      local choice = info[2]
      if not from.dead then
        if table.insertIfNeed(invoked, from.id) then
          room:notifySkillInvoked(from, zhengu.name, "control", {player.id})
          player:broadcastSkillInvoke(zhengu.name)
          room:doIndicate(from.id, {player.id})
        end
        doZhengu(player, from, choice)
      end
    end
  end,
}
zhengu:addRelatedSkill(zhengu_delay)
haozhao:addSkill(zhengu)

Fk:loadTranslationTable{
  ["efengqi__zhengu"] = "镇骨",
  [":efengqi__zhengu"] = "结束阶段，你可以选择两次令一名角色："..
  "<br>①摸两张牌并受到你的1点冰冻伤害；"..
  "<br>②将手牌调整至与你相同。"..
  "<br>若第二次选择同一项，延迟至其下个回合结束执行。",
  ["#efengqi__zhengu-choose"] = "镇骨：选择一名角色，对其造成冰伤害，或令其调整手牌",
  ["#efengqi__zhengu-choice"] = "镇骨：对 %src 执行一项（第 %arg 项，共 2 项）",
  ["#efengqi__zhengu_delay"] = "镇骨",
  ["@@efengqi__zhengu"] = "镇骨",
  ["efengqi__zhengu_damage"] = "令其摸2牌并受到1点冰伤",
  ["efengqi__zhengu_adjust"] = "令其将手牌调整至与你相同",

  ["$efengqi__zhengu1"] = "镇守城池，必以骨相拼！",
  ["$efengqi__zhengu2"] = "孔明计虽百算，却难敌吾镇骨千具！",
}

local zhugezhan = General(extension, "efengqi__zhugezhan", "shu", 3)
local zuilun = fk.CreateTriggerSkill{
  name = "efengqi__zuilun",
  anim_type = "control",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and target:hasSkill(self) and player.phase == Player.Finish
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local n = 0
    if #room.logic:getActualDamageEvents(1, function (e)
      return e.data[1].from == player
    end, Player.HistoryTurn) > 0 then
      n = n + 1
    end
    local events = room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
      for _, move in ipairs(e.data) do
        if move.from == player.id and move.moveReason == fk.ReasonDiscard and table.find(move.moveInfo, function (info)
          return info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip
        end) then
          return true
        end
      end
    end, Player.HistoryTurn)
    if #events == 0 then
      n = n + 1
    end
    if table.every(room.alive_players, function(p) return p:getHandcardNum() >= player:getHandcardNum() end) then
      n = n + 1
    end
    local prompt = n > 0 and "#efengqi__zuilun-invoke:::"..n or "#efengqi__zuilun-duel"
    if room:askForSkillInvoke(player, self.name, nil, prompt) then
      self.cost_data = n
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = self.cost_data
    room:askForGuanxing(player, room:getNCards(3), nil, nil, self.name, false)
    if n > 0 then
      player:drawCards(n, self.name)
    else
      U.askForUseVirtualCard(room, player, "duel", nil, self.name, nil, false)
    end
  end,
}
local fuyin = fk.CreateTriggerSkill{
  name = "efengqi__fuyin",
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  times = function (self)
    return 1 - Self:usedSkillTimes(self.name)
  end,
  events = {fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.card and table.contains({"slash", "duel"}, data.card.trueName)
    and player:usedSkillTimes(self.name) == 0 then
      local from = data.from
      return from and player:getHandcardNum() <= from:getHandcardNum()
    end
  end,
  on_use = Util.TrueFunc,
}
zhugezhan:addSkill(zuilun)
zhugezhan:addSkill(fuyin)
Fk:loadTranslationTable{
  ["efengqi__zhugezhan"] = "诸葛瞻",
  ["#efengqi__zhugezhan"] = "临难死义",
  ["cv:efengqi__zhugezhan"] = "漠桀",
  ["designer:efengqi__zhugezhan"] = "低调的温柔",
  ["illustrator:efengqi__zhugezhan"] = "zoo",

  ["efengqi__zuilun"] = "罪论",
  [":efengqi__zuilun"] = "结束阶段，你可卜算3，你每满足以下一项便摸一张牌：1.你于此回合内造成过伤害；2.你于此回合内未弃置过牌；3.手牌数为全场最少。若均不满足，你视为使用一张【决斗】。",

  ["#efengqi__zuilun-invoke"] = "罪论：你可以卜算3，然后摸 %arg 张牌",
  ["#efengqi__zuilun-duel"] = "罪论：你可以卜算3，然后使用【决斗】！",
  ["#efengqi__zuilun-choose"] = "罪论：选择一名其他角色，你与其各失去1点体力",

  ["efengqi__fuyin"] = "父荫",
  [":efengqi__fuyin"] = "锁定技，你每回合首次受到【杀】或【决斗】的伤害时，若你的手牌数不大于来源，防止之。",

  ["$efengqi__zuilun1"] = "吾有三罪，未能除黄皓、制伯约、守国土。",
  ["$efengqi__zuilun2"] = "唉，数罪当论，吾愧对先帝恩惠。",
  ["$efengqi__fuyin1"] = "得父荫庇，平步青云。",
  ["$efengqi__fuyin2"] = "吾自幼心怀父诫，方不愧父亲荫庇。",
  ["~efengqi__zhugezhan"] = "临难而死义，无愧先父。",
}



return extension
